﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.BLL;
using System.Collections;

namespace EnvironmentManagerSystem.HuanTong
{
    public partial class HPindex : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                if (Session["UserName"].ToString().Length > 4)
                {
                    use.Text = Session["UserName"].ToString().Substring(0, 4);
                    use.ToolTip = Session["UserName"].ToString();
                }
                else
                {
                    use.Text = Session["UserName"].ToString();
                    use.ToolTip = Session["UserName"].ToString();
                }
                time.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                la.Text = Session["roleid"].ToString();
                labID.Text = Session["roleid"].ToString();               
                Binds();
                BindCounts();
            }
        }
        #region 职能显示(x)
        public void Binds()
        {
            if (Session["UserName"] != null && !Session["UserName"].ToString().Equals("") && !Session["UserName"].ToString().Equals("无"))
            {
                if (Session["UserName"].ToString() == "环境局管理员")
                {
                    lblZhiNeng.Text = "(管理员)";
                }
                else
                {
                    renDataCollection list = ren.GetUser(Session["UserName"].ToString());
                    if (list.Count > 0)
                    {
                        if (list[0].Zhineng.ToString() != "" && list[0].Zhineng != null)
                        {
                            lblZhiNeng.Text = "(" + list[0].Zhineng.ToString() + ")";
                            Session["ZhiNeng"] = list[0].Zhineng.ToString();
                            Session["RYID"] = list[0].ID1.ToString();
                        }
                    }
                }
            }
        }
        #endregion

        #region 流程(x)
        private void BindCounts()
        {
            foreach (char zhineng in lblZhiNeng.Text)
            {
                #region (zhineng == "厅长")
                if (lblZhiNeng.Text == "(厅长)")
                {
                    //1项目受理(项目受理确认人为空)
                    this.labXiangMuShouLiDaiQueRen.Text = "待受理项目：" + BLL.HuanPingService.GetCount("SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui is NULL") + "条";
                    if (labXiangMuShouLiDaiQueRen.Text == "待受理项目：0条")
                    {
                        labXiangMuShouLiDaiQueRen.Visible = false;
                    }
                    else
                    {
                        labXiangMuShouLiDaiQueRen.Visible = true;
                    }
                    //2人员分配(项目必须以受理and分配确认人为空)
                    this.lblBuMenFengPei.Text = "待分配项目：" + BLL.HuanPingService.GetCount("SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 and renyuanfenpeirenyuan is NULL") + "条";
                    if (lblBuMenFengPei.Text == "待分配项目：0条")
                    {
                        lblBuMenFengPei.Visible = false;
                    }
                    else
                    {
                        lblBuMenFengPei.Visible = true;
                    }
                    ////3起草文件(项目必须以受理and起草文件人为空)(wenjian IS NULL OR (wenjian=1 AND NOT FIND_IN_SET('厅长',(SELECT zhineng FROM renyuan WHERE username=qicaowenjianrenyuan))))
                    //this.lblXiangMuFeZe.Text = "待起草项目：" + BLL.HuanPingService.GetCount(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND qicaowenjianrenyuan IS NULL") + "条";
                    //if (lblXiangMuFeZe.Text == "待起草项目：0条")
                    //{
                    //    lblXiangMuFeZe.Visible = false;
                    //}
                    //else
                    //{
                    //    lblXiangMuFeZe.Visible = true;
                    //}
//                    //4上传厅长(项目必须以受理and上传厅长人为空)
//                    this.labXianChangTaCha.Text = "待上传项目：" + BLL.HuanPingService.GetCount(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND shangchuantingzrenyuan IS NULL") + "条";
////                        (@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND(querenshangchuan IS NULL OR(querenshangchuan=1
////                                                                                                AND NOT FIND_IN_SET('厅长',(SELECT zhineng FROM renyuan WHERE username=shangchuantingzrenyuan))))") + "条";
//                    if (labXianChangTaCha.Text == "待上传项目：0条")
//                    {
//                        labXianChangTaCha.Visible = false;
//                    }
//                    else
//                    {
//                        labXianChangTaCha.Visible = true;
//                    }
                    //5厅长签发(项目必须以受理and厅长签发人为空)
                    this.labZhuanJiaHuiYi.Text = "待签发项目：" + BLL.HuanPingService.GetCount(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND shangchuantingzrenyuan !='' AND tingzhangqianfaren IS NULL") + "条";
//                        (@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND(qianfa IS NULL OR(qianfa=1
//                                                                                              AND NOT FIND_IN_SET('厅长',(SELECT zhineng FROM renyuan WHERE username=tingzhangqianfaren))))") + "条";
                    if (labZhuanJiaHuiYi.Text == "待签发项目：0条")
                    {
                        labZhuanJiaHuiYi.Visible = false;
                    }
                    else
                    {
                        labZhuanJiaHuiYi.Visible = true;
                    }
                }
                #endregion

                #region (zhineng == "处长")
                if (lblZhiNeng.Text == "(处长)")
                {
                    //1项目受理(项目受理确认人为空)
                    this.labXiangMuShouLiDaiQueRen.Text = "待受理项目：" + BLL.HuanPingService.GetCount("SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui is NULL") + "条";
                    if (labXiangMuShouLiDaiQueRen.Text == "待受理项目：0条")
                    {
                        labXiangMuShouLiDaiQueRen.Visible = false;
                    }
                    else
                    {
                        labXiangMuShouLiDaiQueRen.Visible = true;
                    }
                    //2人员分配(项目必须以受理and分配确认人为空)
                    this.lblBuMenFengPei.Text = "待分配项目：" + BLL.HuanPingService.GetCount("SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 and renyuanfenpeirenyuan is NULL") + "条";
                    if (lblBuMenFengPei.Text == "待分配项目：0条")
                    {
                        lblBuMenFengPei.Visible = false;
                    }
                    else
                    {
                        lblBuMenFengPei.Visible = true;
                    }
//                    //3起草文件(项目必须以受理and起草文件人为空)
//                    this.lblXiangMuFeZe.Text = "待起草项目：" + BLL.HuanPingService.GetCount(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND qicaowenjianrenyuan IS NULL") + "条";
//                        //(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND (querenfenpei IS NULL OR (querenfenpei=1
////                                                                                             AND NOT FIND_IN_SET('处长',(SELECT zhineng FROM renyuan WHERE username=qicaowenjianrenyuan))))") + "条";
//                    if (lblXiangMuFeZe.Text == "待起草项目：0条")
//                    {
//                        lblXiangMuFeZe.Visible = false;
//                    }
//                    else
//                    {
//                        lblXiangMuFeZe.Visible = true;
//                    }
                    //4上传厅长(项目必须以受理and上传厅长人为空)
                    this.labXianChangTaCha.Text = "待上传项目：" + BLL.HuanPingService.GetCount(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND qicaowenjianrenyuan IS NOT NULL AND shangchuantingzrenyuan IS NULL") + "条";
//                        (@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND(querenshangchuan IS NULL OR(querenshangchuan=1
//                                                                                                AND NOT FIND_IN_SET('处长',(SELECT zhineng FROM renyuan WHERE username=shangchuantingzrenyuan))))") + "条";
                    if (labXianChangTaCha.Text == "待上传项目：0条")
                    {
                        labXianChangTaCha.Visible = false;
                    }
                    else
                    {
                        labXianChangTaCha.Visible = true;
                    }
                }
                #endregion

//                #region (zhineng == "科员")
//                if (lblZhiNeng.Text == "(科员)")
//                {
//                    //1项目受理(项目受理确认人为空)
//                    this.labXiangMuShouLiDaiQueRen.Text = "待受理项目：" + BLL.HuanPingService.GetCount("SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui is NULL") + "条";
//                    if (labXiangMuShouLiDaiQueRen.Text == "待受理项目：0条")
//                    {
//                        labXiangMuShouLiDaiQueRen.Visible = false;
//                    }
//                    else
//                    {
//                        labXiangMuShouLiDaiQueRen.Visible = true;
//                    }
//                    //2人员分配(项目必须以受理and分配确认人为空)
//                    this.lblBuMenFengPei.Text = "待分配项目：" + BLL.HuanPingService.GetCount("SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 and renyuanfenpeirenyuan is NULL") + "条";
//                    if (lblBuMenFengPei.Text == "待分配项目：0条")
//                    {
//                        lblBuMenFengPei.Visible = false;
//                    }
//                    else
//                    {
//                        lblBuMenFengPei.Visible = true;
//                    }
//                    //3起草文件(项目必须以受理and起草文件人为空)
//                    this.lblXiangMuFeZe.Text = "待起草项目：" + BLL.HuanPingService.GetCount(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND qicaowenjianrenyuan IS NULL") + "条";
////                        (@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND (wenjian IS NULL OR (wenjian=1
////                                                                                             AND NOT FIND_IN_SET('科员',(SELECT zhineng FROM renyuan WHERE username=qicaowenjianrenyuan))))") + "条";
//                    if (lblXiangMuFeZe.Text == "待起草项目：0条")
//                    {
//                        lblXiangMuFeZe.Visible = false;
//                    }
//                    else
//                    {
//                        lblXiangMuFeZe.Visible = true;
//                    }
//                }
//                #endregion

                #region (zhineng == "经办人")
                if (lblZhiNeng.Text == "(经办人)")
                {
                    //3起草文件(项目必须以受理and起草文件人为空)
                    this.lblXiangMuFeZe.Text = "待起草项目：" + BLL.HuanPingService.GetCount(@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND renyuanfenpeirenyuan !='' AND qicaowenjianrenyuan IS NULL") + "条";
                    //                        (@"SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui=1 AND (wenjian IS NULL OR (wenjian=1
                    //                                                                                             AND NOT FIND_IN_SET('科员',(SELECT zhineng FROM renyuan WHERE username=qicaowenjianrenyuan))))") + "条";
                    if (lblXiangMuFeZe.Text == "待起草项目：0条")
                    {
                        lblXiangMuFeZe.Visible = false;
                    }
                    else
                    {
                        lblXiangMuFeZe.Visible = true;
                    }
                }
                #endregion

                #region (zhineng == "受理人")
                if (lblZhiNeng.Text == "(受理人)")
                {
                    //1项目受理(项目受理确认人为空)
                    this.labXiangMuShouLiDaiQueRen.Text = "待受理项目：" + BLL.HuanPingService.GetCount("SELECT COUNT(*) FROM tbs001_huanping WHERE shoulituihui is NULL") + "条";
                    if (labXiangMuShouLiDaiQueRen.Text == "待受理项目：0条")
                    {
                        labXiangMuShouLiDaiQueRen.Visible = false;
                    }
                    else
                    {
                        labXiangMuShouLiDaiQueRen.Visible = true;
                    }
                }
                #endregion
            }
        }
        #endregion
    }
}